package com.doyens.gmall.product.controller;

import com.alibaba.fastjson.JSONObject;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.*;
import com.doyens.gmall.product.service.BaseTardemarkService;
import com.doyens.gmall.product.service.ManageService;
import com.doyens.gmall.product.service.SkuManageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Api(tags = "商品信息接口")
@RestController
//api 提供前台服务的接口
//admin  后台服务的接口
@RequestMapping("api/product")
public class ProductApiController {
    @Autowired
    private SkuManageService skuManageService;
    @Autowired
    private ManageService manageService;
    @Autowired
    private BaseTardemarkService baseTardemarkServic;

    //通过skuid获取sku的信息(sku、图片)
    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId) {
        SkuInfo skuInfo = skuManageService.getSkuInfo(skuId);
        return skuInfo;
    }

    @GetMapping("inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id") Long category3Id){
        BaseCategoryView baseCategoryView =manageService.getCategoryView(category3Id);
        return baseCategoryView;
    }

    @GetMapping("inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable("skuId") Long skuId){
       return skuManageService.getSkuPrice(skuId);
    }

    /**
     * 根据 skuId、spuId查询所有销售属性和当前skuId的销售属性
     * @param skuId
     * @param spuId
     * @return
     */
    @GetMapping("inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable("skuId") Long skuId,
                                                          @PathVariable("spuId")Long spuId){
        return manageService.getSpuSaleAttrListCheckBySku(skuId,spuId);
    }

    @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId") Long spuId){
        Map map = skuManageService.getSkuValueIdsMap(spuId);
        return map;
    }

    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        List<JSONObject> baseCategoryList = manageService.getBaseCategoryList();
        return Result.ok(baseCategoryList);
    }

    @GetMapping("inner/getTrademark/{tmId}")
    public BaseTrademark getBaseTrademark(@PathVariable("tmId") Long tmId){
        BaseTrademark baseTrademark = baseTardemarkServic.getById(tmId);
        return baseTrademark;
    }

    @GetMapping("inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId){
        List<BaseAttrInfo> attrList = manageService.getAttrList(skuId);
        return attrList;
    }
}
